home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / FONT_UTL / GRFTXT / GRAFTEX2.ASM < prev    next >
Assembly Source File  |  1993-03-09  |  7KB  |  206 lines

  1. ; GRAFTEXT - Fast text in graphics mode
  2. ;           Gsol - solid text procedure
  3. ;
  4. ; by Tim Godfrey 72617,2125
  5. ;
  6. ; version 2.0 - 2/19/93  updated for support of protected mode in BP7
  7. ;
  8. data   segment word public
  9.        assume DS:DATA
  10.        extrn   pitch:WORD     ; number of bytes per scan line
  11.        extrn   Seg0040:word
  12.        extrn   SegA000:word
  13. lpage   dw      ?               ; local storage for Page offset
  14.  
  15. data   ends
  16.  
  17.  
  18.  
  19. code      segment   byte public
  20. assume    cs:code,ds:data
  21. public    gsol
  22. page 60,132
  23. ;                   val val val     val      VAR    VAR
  24. ; procedure gsol(gdx,gdy,color,fontlines,fontbase,instring);
  25.  
  26. ; These equates define the BP relative passed parameters
  27. gdx       equ  [BP+20]
  28. gdy       equ  [BP+18]
  29. backgnd   equ  [BP+16]
  30. color     equ  [BP+14]
  31. fontlines equ  [BP+12]
  32. fontbase  equ  [BP+8]
  33. instring  equ  [BP+4]
  34. pitchBP   equ  [BP-4]     ; local pitch variable now stored on stack
  35.                           ; pitch is not a passed parameter- see note below 
  36.  
  37. gsol proc    NEAR
  38.  
  39.      push      bp
  40.      mov       bp,sp
  41.      push      ds
  42.      mov       ax,pitch        ; read pitch out of data segment
  43.      push      ax              ; save pitch on stack at [BP-4]
  44.                                ;
  45.                                ; Note! Do not add anything that would change
  46.                                ; the stack pointer between this push AX and
  47.                                ; the push BP above without making a
  48.                                ; corresponding change to the pitchBP EQU
  49.  
  50.  
  51. ; Calculate byte address (segment & offset) and bit mask
  52.  
  53. ;
  54.      push    ds
  55.      mov     dx,Seg0040         ; bios data segment
  56.      mov     ds,dx
  57.      mov     si,062h
  58.      mov     al,[si]       ; get active display page
  59.      or      al,al
  60.      jz      page0           ; if zero, skip ofset add
  61.      mov     ax,8000h           ; set ax to 8000h
  62.      jmp     setpage
  63. page0:
  64.      xor     ax,ax              ; clear page offset
  65. setpage:
  66.      pop     ds
  67.  
  68.      mov     lpage,ax   ; page offset value
  69.  
  70.      mov     dx,3CEh         ; Graphics Controller port address
  71.      mov     ax,0205h        ; Writemode 2, Readmode 0, index 5
  72.      out     dx,ax           ; select register 5 (mode)
  73.  
  74.      mov     dx,3C4h         ; Sequencer/Map Mode port address
  75.      mov     ax,0F02h
  76.      out     dx,ax           ; Select "Map Mask" register 2, enable all planes
  77.  
  78.  
  79. ;
  80.      mov     bx,gdx          ; get X address from stack frame
  81.      shr     bx,1
  82.      shr     bx,1
  83.      shr     bx,1            ; compute memory address ofset  BX := x/8
  84. ;
  85.      les     SI,instring     ; get doulbleword base address of string
  86.      xor     ch,ch           ; clear ch
  87.      mov     cl,byte ptr ES:[si]  ; points to length of string
  88.      or      cl,cl        ; set flags
  89.      jz         nullstring      ; if length is zero, skip everything
  90.  
  91.      mov     ax,gdy          ; get Y address (a pixel row)
  92.      add     ax,fontlines           ; add in lines in font as ofset to Y value
  93.      dec     ax              ; subtract 1 because cx is 1 based inst. of 0
  94.      mov     dx,pitch        ; DS is still correct
  95.      mul     dx              ; AX := (y * 80)  ([pitch] bytes per row)
  96.      add     dx,lpage   ; add in page offset;
  97.      add     ax,bx           ; AX := (y * 80) + x/8          (offset)
  98.  
  99.      mov     di,ax           ; save EGA/VGA memory ofset in DI
  100.  
  101.      mov     dx,SegA000       ; base page of EGA/VGA memory
  102.                              ; note: this variable is in main DS
  103.      mov     ds,dx           ; DS := EGA/VGA buffer segment address
  104.  
  105. ; Get the Graphics Controller register address
  106.      mov     dx,3CEh         ; base: (offset is 8 for bitmask register)
  107.  
  108. strloop:                     ; loop for number of characters in string
  109.      push    CX              ; save string count for outer loop
  110.      inc     SI              ; make si point to nextchar
  111.      mov     bl,byte ptr ES:[SI]      ; SI points to next char - read into bx
  112.      inc     bl              ; increment char code : draw char from bot to top
  113.      mov     ax,fontlines    ; get number of lines/char in font
  114.      mov     cx,ax           ; keep for use as char-loop counter
  115.      mul     bl              ; ax := bl (character) * al (bytes/char)
  116.      mov     bx,ax           ; leave font character ofset in BX
  117.      push    ES              ; save char string seg.
  118.      push    SI              ; save char string pointer
  119.      push    DI              ; save EGA/VGA destination
  120. ;
  121. ; loop for the number of lines
  122. ;
  123.  
  124.      les     SI,fontbase     ; get dblword base address of font
  125. ;
  126. ;
  127.      dec     cx              ; one less pass thru loop, due to early latch read
  128.  
  129.      dec     bx              ; move UP to next scanline in font
  130.  
  131.      mov     ax,0FF08h            ; bit mask index = 8, mask = FFh
  132.      out     dx,ax           ; enable all bits in bit mask into reg 8
  133. ;                            ; preserve bitmap index: 8 in AL
  134.  
  135.      mov     ah,byte ptr backgnd
  136.      mov     [di],ah         ; Set all bits to "backgnd color".
  137.  
  138.      mov     ah,[di]         ; Latch the bit plane data with dummy read
  139.                              ; latch only once for all writes this character
  140.  
  141. charloop:                    ; loop through the font's scanlines bottom to top
  142.  
  143.  
  144. ; Set bits in the appropriate bit planes by writing color value to EGA/VGA memory
  145.  
  146.      mov     ah,ES:[BX][SI]  ; get bit mask byte from font: bx=font char ofs
  147.      out     dx,ax           ; load bit mask into reg 8
  148.  
  149.      mov     ah,color
  150.      mov     [di],ah         ; write foreground color with bit mask.
  151.  
  152. ;                            ; read pitch from BP stack frame
  153.      sub     di,pitchBP      ; move up one line in EGA/VGA memory
  154.  
  155.      dec     bx              ; move UP to next scanline in font
  156.  
  157.      mov     ah,0FFh
  158.      out     dx,ax           ; enable all bits in bit mask, reg 8
  159. ;
  160.      mov     ah,backgnd
  161.      mov     [di],ah         ; Set all bits to "backgnd color".
  162.  
  163.  
  164.      loop    charloop        ; decrement cx and do next scanline
  165.  
  166.                              ; perform final foreground write
  167.  
  168.      mov     ah,ES:[BX][SI]  ; get bit mask byte from font: bx=font char ofs
  169.      out     dx,ax           ; load bit mask into reg 8
  170.  
  171.      mov     ah,color
  172.      mov     [di],ah         ; write foreground color with bit mask.
  173.  
  174.  
  175.      pop     DI              ; get back EGA/VGA destination
  176.      inc     DI              ; move screen position to next char over
  177.  
  178.      pop     SI              ; pop character pointer
  179.      pop     ES              ;  "     "      segment
  180.  
  181.      pop     CX              ; get outer loop - counting chars in string
  182.      loop    strloop
  183.  
  184. nullstring:
  185. ; Restore default EGA/VGA graphics status
  186.  
  187.  
  188.  
  189.                              ; dx already points do Graphics Controller
  190.      mov     ax,0005h        ; write mode=0; read mode=0; index =5
  191.      out     dx,ax           ; select register 5 (mode)
  192.  
  193.      mov     ax,0FF08h        ; reset bitmask register to all on
  194.      out     dx,ax           ; ... Graphics Controller register 8
  195.  
  196.      pop       ax            ; discard pitch value from stack frame
  197.      pop       ds
  198.      pop       bp
  199.      ret       16d
  200. gsol endp
  201.  
  202. code ends
  203.  
  204.      end
  205.  
  206.